<?php

class book {
    //私有属性
    private int $id;
    private string $name;
    private float $price;

    /**
     * @param int $id
     * @param string $name
     * @param float $price
     */
    public function __construct(int $id, string $name, float $price) {
        $this->id = $id;
        $this->name = $name;
        $this->price = $price;
    }

    public function getId(): int {
        return $this->id;
    }

    public function setId(int $id): book {
        $this->id = $id;
        return $this;
    }

    public function getName(): string {
        return $this->name;
    }

    public function setName(string $name): book {
        $this->name = $name;
        return $this;
    }

    public function getPrice(): float {
        return $this->price;
    }

    public function setPrice(float $price): book {
        $this->price = $price;
        return $this;
    }

    public function __toString(): string {
        return sprintf("书籍名称：%s，编号：%d，价格：%f元。", $this->name, $this->id, $this->price);
    }

    public function __destruct() {
        echo "销毁book对象";
    }
}